import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { Observable } from 'rxjs';

@Injectable()
export class AaaGuard implements CanActivate {
 

  constructor(private reflector: Reflector){}


  canActivate(
    context: ExecutionContext,
  ): boolean | Promise<boolean> | Observable<boolean> {
    console.log('guard');

    //拿到roles角色在handler上的装饰器,进而判断其权限
    console.log(this.reflector.get('roles',context.getHandler()));
    //拿到roles角色在class上的装饰器,进而判断其权限
    console.log(this.reflector.get('roles',context.getClass()));
    return true;
  }


}
